home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-03 | 2.9 KB | 126 lines | [TEXT/PJMM] |
- (* Platform sprite, experimental faceless sprite *)
-
- unit sPlatForm;
- interface
- uses
- {$ifc UNDEFINED THINK_PASCAL}
- Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {}
- {$endc}
- SAT, PlatformGlobals, sPlayerSprite;
-
- procedure InitPlatform;
- procedure HandlePlatform (me: SpritePtr);
- procedure HitPlatform (me: SpritePtr; him: PlSpritePtr);
- procedure SetupPlatform (me: SpritePtr);
-
- implementation
-
- procedure InitPlatform;
- (* nada*)
- begin
- end;
-
- procedure HandlePlatform (me: SpritePtr);
- (*me->face = nil;*)
- begin
- end;
-
- procedure HitPlatform (me: SpritePtr; him: PlSpritePtr);
- var
- mini, i, min: Integer;
- diff: array[0..5] of Integer;
- begin
- if (him^.task = @HandlePlayerSprite) then
- begin
- diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom); (* TtoB *)
- diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom); (* BtoT *)
- diff[3] := -me^.hotRect2.left + (him^.hotRect2.right); (* LtoR *)
- diff[4] := -him^.hotRect2.left + (me^.hotRect2.right); (* RtoL *)
- mini := 0;
- min := 10000;
- for i := 1 to 4 do
- begin
- if (min > diff[i]) then
- begin
- min := diff[i];
- mini := i;
- end; (* if *)
- end;
- case mini of
- 1: (*floor*)
- begin
- him^.action := Stand;
- him^.position.v := him^.position.v - diff[1] + 1;
- if (him^.speed.v > 0) then
- him^.speed.v := 0;
- him^.speed.h := 0;
- end;
- 2: (* ceiling *)
- begin
- him^.position.v := him^.position.v + diff[2] + 1;
- if (him^.speed.v < 0) then
- him^.speed.v := -him^.speed.v;
- end;
- 3: (*left*)
- begin
- him^.position.h := him^.position.h - diff[3] - 1;
- if (him^.speed.h > 0) then
- him^.speed.h := -him^.speed.h;
- end;
- 4: (*right*)
- begin
- him^.position.h := him^.position.h + diff[4] + 1;
- if (him^.speed.h < 0) then
- him^.speed.h := -him^.speed.h;
- end;
- end; (* switch *)
- end;
- end;
-
- procedure SetupPlatform (me: SpritePtr);
- var
- r: Rect;
- pol: PolyHandle;
-
- begin
- me^.task := @HandlePlatform;
- me^.hitTask := @HitPlatform;
-
- me^.face := nil; (* = faceless! *)
- SetRect(me^.hotRect, 0, 0, 100, 16);
- r := me^.hotRect;
- OffsetRect(r, me^.position.h, me^.position.v);
- SATSetPortBackScreen;
- ForeColor(cyanColor);
- {$ifc UNDEFINED THINK_PASCAL}
- FillRect(r, qd.dkGray);
- {$ELSEC}
- FillRect(r, dkGray);
- {$endc}
-
- pol := OpenPoly;
- MoveTo(r.left, r.top);
- LineTo(r.left + 5, r.top - 5);
- LineTo(r.right + 5, r.top - 5);
- LineTo(r.right, r.top);
- LineTo(r.left, r.top);
- LineTo(r.right, r.top);
-
- LineTo(r.right, r.bottom);
- LineTo(r.right + 5, r.bottom - 5);
- LineTo(r.right + 5, r.top - 5);
- LineTo(r.right, r.top);
-
- ClosePoly;
- ErasePoly(pol);
- FramePoly(pol);
- KillPoly(pol);
-
- r.top := r.top - 5;
- r.right := r.right + 5;
- SATBackChanged(r); (* Tell SAT to draw it when appropriate *)
-
- me^.layer := -me^.position.v;
- end;
-
- end.